package com.wzx.user.sdk.service.impl;

import com.wzx.common.exception.LeadNewsException;
import com.wzx.user.sdk.common.oss.OssTemplate;
import com.wzx.user.sdk.service.OssService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;

/**
 * @author wzx
 * @version 1.0
 * @date 2022/7/22 - 15:57
 * @description 标题
 */
@Service
@Slf4j
public class OssServiceImpl implements OssService {

    @Autowired
    private OssTemplate ossTemplate;

    @Override
    public String upload(MultipartFile file) throws IOException, LeadNewsException {
        //上传头像，得到头像url
        String fileName = file.getOriginalFilename();
        log.info("文件名为：{}",fileName);
        if (StringUtils.isEmpty(fileName)){
            throw new LeadNewsException("文件名称为空！");
        }
        return ossTemplate.upload(fileName,file.getInputStream());
    }
}
